//
//  KeyboardViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/28.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift
import RxKeyboard

class KeyboardViewController: BaseViewController {

    let disposed = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let scrollView = UIScrollView(frame: self.view.bounds)
        self.view.addSubview(scrollView)
        
        let textField = UITextField(frame: CGRect(x: 0, y: self.view.height - 40 - 64, width: self.view.width, height: 40))
        textField.backgroundColor = UIColor.lightGray.withAlphaComponent(0.2)
        
        scrollView.addSubview(textField)
        scrollView.alwaysBounceVertical = true
        
        self.view.addTapWithHandle { (tap) in
            scrollView.endEditing(true)
        }
        
        RxKeyboard.instance.frame
            .drive(onNext: { frame in
                print(frame)
                textField.y = frame.origin.y - 64 - textField.height
            })
            .disposed(by: disposed)
        
        scrollView.keyboardDismissMode = .interactive
    }
    

}
